<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script language="JavaScript">
var sales_id = '{{.sales_id}}';
var dataTables = $('#dataTables').DataTable({
    order:[]
    ,columns: [
        {"bSortable": false, render:function(data, type, full, meta) {
                return productTypeidName(full.Products.TypeId);
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return productGroupName(full.Products);
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
               var html = [];
               switch (full.Products.TypeId) {
                   case 10:
                       html.push('<span>球镜:'+ full.Snd.sph +'</span></br>');
                       html.push('<span>柱镜:'+ full.Snd.cyl +'</span>');
                       break;
                   case 20:
                       html.push('<span>球镜:'+ full.Snd.sph +'</span></br>');
                       html.push('<span>柱镜:'+ full.Snd.cyl +'</span>');
                       break;
                   case 30:
                       html.push("<span>型号:"+full.Snd.model+"</span></br>");
                       html.push("<span>色号:"+full.Snd.color+"</span></br>");
                       html.push("<span>尺寸:"+full.Snd.size+"</span></br>");
                       html.push("<span>框型:"+full.Snd.genre+"</span>");
                       break;
                   case 40:
                       html.push("<span>球镜:"+full.Snd.sph+"</span></br>");
                       html.push('<span>ADD:'+ full.Snd.add +'</span>');
                       break;
                   case 41:
                       html.push("<span>型号:"+full.Snd.model+"</span></br>");
                       html.push("<span>色号:"+full.Snd.color+"</span></br>");
                       html.push("<span>尺寸:"+full.Snd.size+"</span></br>");
                       html.push("<span>框型:"+full.Snd.genre+"</span></br>");
                       html.push("<span>膜层颜色:"+full.Snd.film_color+"</span></br>");
                       html.push("<span>功效:"+full.Snd.function_info+"</span>");
                       break;
                   case 60:
                       break;
               }
               return html.join('')
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Inventory.Acceptance.lot_number ? full.Inventory.Acceptance.lot_number : '';
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Inventory.Acceptance.manufacture_date ? timetransDate(full.Inventory.Acceptance.manufacture_date) : '';
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Inventory.Acceptance.expiry_date ? timetransDate(full.Inventory.Acceptance.expiry_date) : '';
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.OriginalPrice;
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.DiscountRate;
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.UnitPrice;
        }}
        ,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Amount;
        }}
    ]
    ,"serverSide": false
    ,"bPaginate" : false
    ,"bFilter" : false	//是否启动过滤、搜索功能
    ,"bInfo" : false //是否显示页脚信息，DataTables插件左下角显示记录数
    ,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示
    ,"drawCallback": function(settings){
    }
});

//获取单据明细
$.post('', {'sales_id':sales_id}, function (res) {
    if(res.code == 1) {
        layer.msg(res.msg);return false;
    }
    var retail = res.data.retail;
    var retail_data = res.data.retail_data;
    setHtmlText(retail.Archives); //设置基本资料
    setHtmlText(retail); //设置单据信息

    var tableBox = $('#dataTables').find('tbody');

    var dt = $('#dataTables').DataTable();
    $.each(retail_data, function (index, value) {
        dt.row.add(value).draw();
    });
    $("#payinfo").find(".widget-title").html("退款信息--------合计退款:<span style='color:red;'>￥"+retail.SumPayable+"</span>");
}, 'json');

var setHtmlText = function (data) {
    $.each(data, function (idx, val) {
        if(idx == 'HopePickUpTime') {
            val ? $('#'+idx).text(timetransDate(val)) : '';
        } else {
            $('#'+idx).text(val);
        }
    });
};

</script>